<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of AdminFromsAbstract
 *
 * @author hodek
 */
abstract class AdminFormsAbstract {
    
    protected static function getDelete($adminForm){        
        $GLOBALS["editId"] = selectItemid($adminForm[0]);
        $GLOBALS["editContent"] = $adminForm[1];
        return parse(loadTemplate(null, "deleteItem")).parse(loadTemplate(null, "deleteConfirm"));        
    }


    protected static function getVisibilityLink($adminForm){
        $GLOBALS["editId"] = $adminForm[0];
        $GLOBALS["editContent"] = $adminForm[1];
        return parse(loadTemplate(null, "visibilityItem"));        
    }

    public static function editText($name, $content = null, $isOneLine = false) {
        if (isAdmin()) {
            $GLOBALS["specialClass"] = "specialClassTextEdit";
            global $editId;
            global $editContent;
            $editId = $name;
            if ($content == null) {
                $content = fetch(selectText($name));
                $content = $content["data"];
            }
            $editContent = $content;
            if ($isOneLine) {
                $editContent = parse(loadTemplate(null, "editTextSingleLine"));
            } else {
                $editContent = parse(loadTemplate(null, "editText"));
            }
            return (parse(loadTemplate(null, "editLink")) . parse(loadTemplate(null, "editWindow")));
        }
    }
    
    public static function addCat($catName){
        if (isAdmin()){
            $GLOBALS["catName"] = $catName;
            $GLOBALS["specialClass"] = "specialClassAdd";
            return parse(loadTemplate(null, "addCat"));
        }
    }

    /**
     * FormFragment
     */
    protected static function getFFText($adminFrom, $isOneLine = false) {
        $GLOBALS["editId"] = $adminFrom[0];
        $GLOBALS["editContent"] = $adminFrom[1];        
        if ($isOneLine) {
            $ret = parse(loadTemplate(null, "editTextSingleLine"));
        } else {
            $ret = parse(loadTemplate(null, "editText"));
        }
        return $ret;
    }
    
    protected static function getFFHidden($adminForm){
        $GLOBALS["editId"] = $adminForm[0];
        $GLOBALS["editContent"] = urlencode($adminForm[1]);
        return parse(loadTemplate(null, "editHidden"));
    }

    protected static function getFFDate($adminForm) {
        $GLOBALS["editId"] = $adminForm[0];
        $GLOBALS["editContent"] = dbDateToCalendarDate($adminForm[1]);
        return parse(loadTemplate(null, "editDate"));
    }

    protected static function getFFImage($imageName) {
        $GLOBALS["editId"] = $imageName;
        return parse(loadTemplate(null, "editImage"));
    }

    protected static function getFFDynSimpleImage($adminFrom) {
        
    }

    protected static function getFFDivider() {
        return '<div class="editContentDivider"></div>';
    }

    protected static function getIcoEditFFLinkAndWindow($content,$specialClass = "") {
        $GLOBALS["editId"] = "formRandom_" . rand();
        $GLOBALS["editContent"] = $content;
        $GLOBALS["specialClass"] = "specialClass".$specialClass;
        return (parse(loadTemplate(null, "editLink")) . parse(loadTemplate(null, "editWindow")));
    }

    public static function editCat($special = null) {
        if (!isAdmin())
            return "";
        if ($special != null) {
            return AdminForms::editCatSpecial($special);
        } else {
            $content = "";
            $isFirst = true;
            foreach (getAdminFrom() as $value) {
                if ($isFirst) {
                    $content .= AdminFormsAbstract::getFFText($value, true);
                    $isFirst = false;
                } else {
                    $content .= AdminFormsAbstract::getFFDivider();
                    $content .= AdminFormsAbstract::getFFText($value);
                }
            }
            return AdminFormsAbstract::getIcoEditFFLinkAndWindow($content,"side");
        }        
    }

    /**
     * Zavola se pokud je nastaven special ${CAT_EDIT_SPECIAL}
     * 
     * @param type $special
     * @return type 
     */
    public abstract function editCatSpecial($special);
    
    public abstract function customForm($first = null, $second = null, $third = null);
}

?>
